package cn.itcast.listener;

import cn.itcast.domain.system.User;
import cn.itcast.utils.MailUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

public class EmailListener implements MessageListener {

    private ObjectMapper objectMapper=new ObjectMapper();

    @Override
    public void onMessage(Message message) {
        byte[] body = message.getBody();
        try {
            User user = objectMapper.readValue(body, User.class);
            //发送邮件
            /**
             * 参数一：接受人
             * 参数二：邮件的主题
             * 参数三：邮件的正文内容
             */
            MailUtil.sendMsg(user.getEmail(),"欢迎你加入传智播客","在传智没有九九六，只有用爱成就每一位学员");
            System.out.println("发送邮件成功!");
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
